<?php
namespace Admin\Controller;
class CommentController extends BaseController 
{
    public function add()
    {
    	if(IS_POST)
    	{
    		$model = D('Comment');
    		if($model->create(I('post.'), 1))
    		{
    			if($id = $model->add())
    			{
    				$this->success('添加成功！', U('lst'));
    				exit;
    			}
    		}
    		$this->error($model->getError());
    	}

		// 设置页面中的信息
	
		$this->display();
    }
    public function edit()
    {
    	$id = I('get.id');
    	if(IS_POST)
    	{
    		$model = D('Comment');
    		if($model->create(I('post.'), 2))
    		{
    			if($model->save() !== FALSE)
    			{
    				$this->success('修改成功！', U('lst'));
    				exit;
    			}
    		}
    		$this->error($model->getError());
    	}
    	$model = M('Comment');
    	$data = $model->find($id);
    	$this->assign('data', $data);

		
		$this->display();
    }
    public function delete()
    {
    	$model = D('Comment');
    	if($model->delete(I('get.id', 0)) !== FALSE)
    	{
    		$this->success('删除成功！', U('lst', array('p' => I('get.p', 1))));
    		exit;
    	}
    	else 
    	{
    		$this->error($model->getError());
    	}
    }
    public function lst()
    {
    	
    	$model = D('Comment');
    	$commentdata = $model->alias('a')->field('a.*,b.goods_name,c.name')->join('left join s50_goods b on a.goods_id = b.id left join s50_member c on a.member_id = c.id')->select();
    	//echo '<pre>';
    	//var_dump($commentdata);die();
    	$this->assign(array(
    		'commentdata' => $data,
    	));
    	//var_dump($data);die();
    	$demo = $model->search();
    	//echo '<pre>';
    	//var_dump($demo);die();
    	$this->assign(array(
    		'commentdata'=>$commentdata,
    		'data'=>$demo['data'],
    		'page'=>$demo['page'],
    	));
    	//var_dump($demo);die();
    	//$this->assign($demo);
    	$this->display();
    	
    }
}